import React from "react";
import {useRoutes} from "react-router-dom";
import NotFound from "@/views/notFound/index.jsx";
import Login from "@/views/login/index.jsx";
import homeRouter from "@/router/modules/home.jsx";
import menuRouter from "@/router/modules/menu.jsx";
import proTableRouter from "@/router/modules/proTable.jsx";

// 动态路由 : 应该导入整个文件夹中的模块才是最优解
const allRouters = [
    homeRouter,
    menuRouter,
    proTableRouter,
]
const metaRouters = []

// * 处理路由
allRouters.forEach(item => {
    metaRouters.push(...item)
})

// 静态路由
const staticRouter = [
    {
        path: "/login",
        name: "Login",
        element: <Login/>,
        meta: {
            requiresAuth: false,
            title: "登录页",
            key: "login"
        }
    },
    {
        path: "*",
        name: "NotFound",
        element: <NotFound/>,
        meta: {
            requiresAuth: false,
            title: "404",
            key: "NotFound"
        }
    },
]

export const rootRouter = [
    ...metaRouters,
    ...staticRouter
]

export default function useMyRouter() {
    return useRoutes(rootRouter)
}
